function partition(arr, p, q) {
  let x = arr[p];
  let i = p;
  for (let j = p + 1; j <= q; j++) {
    if (arr[j] <= x) {
      i++;
      swap(arr, i, j);
    }
  }
  swap(arr, i, p);
  return i;
}
function swap(arr, i, j) {
  let temp = arr[i];
  arr[i] = arr[j];
  arr[j] = temp;
}

function quickSort(arr, p, q) {
  if (p >= q) return;
  let k = partition(arr, p, q);
  quickSort(arr, 0, k - 1);
  quickSort(arr, k + 1, q);
}
let arr = [2, 3, 1, 5, 2];
quickSort(arr, 0, arr.length - 1);
console.log(arr);
